<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="mb.commons.DbConnection"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% HttpSession sesja = request.getSession(true); %>
<%
response.setContentType("text;charset=UTF-8");
String value=new String(request.getParameter("adres").getBytes("ISO8859_1"), "UTF8");
String[] tab = value.split(", ");
String[] tab2 = tab[1].split(" ");
if(sesja.getAttribute("log").equals("kurier")){ 
	 String nick = (String)sesja.getAttribute("nick");
	 System.out.println(nick);
	 String odp="<table>";
	 String odp2="<select id='status' name='status'>";
		try {
		  Connection con =mb.commons.DbConnection.getConnection();
		  Statement stmt = con.createStatement();
		  ResultSet rs2 = stmt.executeQuery("SHOW COLUMNS FROM zamowienia WHERE field LIKE  'status'");
		  while(rs2.next()){
			  String enumer = rs2.getString("type");
			  String[] taber = enumer.split("[/'(.*?)'/,;]");
			  for(int i=1;i<taber.length;i++){
				  if(!taber[i].equals(""))
				  odp2+="<option value='"+taber[i]+"'>"+taber[i]+"</option>";
			  }
		  }
		  rs2.close();
		  ResultSet rs = stmt.executeQuery("SELECT * FROM zamowienia, kurierzy,uzytkownicy,oddzialy,paczki WHERE uzytkownicy.login='"+nick+"' AND kurierzy.id = uzytkownicy.id AND kurierzy.id_kuriera = zamowienia.id_kuriera AND kurierzy.id_oddzialu=oddzialy.id AND paczki.id_paczki=zamowienia.id_paczki AND paczki.adres2 LIKE '%"+tab[0]+"%' AND paczki.miejscowosc2 LIKE '%"+tab2[1]+"%'");
		  
		  while(rs.next()){
			odp+="<tr><td>Imie odbiorcy:</td><td>"+rs.getString("paczki.imie2")+"</td></tr>";
			odp+="<tr><td>Nazwisko odbiorcy:</td><td>"+rs.getString("paczki.nazwisko2")+"</td></tr>";
			odp+="<tr><td>Adres odbiorcy:</td><td>"+rs.getString("paczki.adres2")+"</td></tr>";
			odp+="<tr><td>Kod pocztowy odbiorcy:</td><td>"+rs.getString("paczki.kod2")+"</td></tr>";
			odp+="<tr><td>Miejscowosc odbiorcy:</td><td>"+rs.getString("paczki.miejscowosc2")+"</td></tr>";
			odp+="<tr><td>Do zaplaty:</td><td>"+rs.getString("paczki.oplata")+"</td></tr>";
			odp+="<tr><td>Pobranie:</td><td>"+rs.getString("paczki.pobranie")+"</td></tr>";
			odp+="<tr><td><form method=post action='status?dir=do'>"+odp2+"</select></td><td><input type=hidden id='idpaczki' name='idpaczki' value="+rs.getInt("id_zamowienia")+"><input type=submit value='Zmien status'></form></td></tr>";
		  }	  
		  out.println(odp+"</table><br><a href='trasa2.jsp'>Powrot.</a>");
		  
		} catch (Exception e) {
			 System.out.println(e);
		}
}
//out.println(value);%>
</body>
</html>